import Vue from 'vue';
import Vuex from 'vuex'
import $http from '@/common/request.js';
Vue.use(Vuex)
export default new Vuex.Store({
	state: {
		user: false,
		totalCount: 0,
		token: '',
		userInfo: {}
	},
	mutations: {
		// 登录
		login(state, res) {
			uni.setStorageSync('token', res.accessToken);
			uni.setStorageSync('userInfo', res.userInfo);
			state.token = res.accessToken;
			state.userInfo = res.userInfo;
		},
		// 退出登录
		logout(state) {
			uni.removeStorageSync('token');
			uni.removeStorageSync('userInfo');
			state.token = '';
			state.userInfo = {};
		},
		updateUserInfo(state, userInfo) {
			uni.setStorageSync('userInfo', userInfo);
			state.userInfo = userInfo;
		},
		isLogin(state) {
			if (state.token) {
				uni.reLaunch({
					url: '/pages/index/index',
				});
			}
		}
	}
})
